package com.hbusa.cotroller.type;

import com.hbusa.dto.TbCategory;
import com.hbusa.service.CategoryService;
import com.hbusa.service.service.impl.CategoryServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet("/doCategoryDelete")
public class CategoryDelete extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        resp.setCharacterEncoding("utf-8");
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;utf-8");

//        int  cat_id = Integer.parseInt(req.getParameter("cat_id"));
//
//        System.out.println(cat_id);
//
        TbCategory category = new TbCategory();
//
//        category.setCatId(cat_id);

//        HttpSession session = req.getSession();
//        long cat_id = (long) session.getAttribute("cat_id");
        //System.out.println(catId);

        long cat_id = Long.parseLong(req.getParameter("cat_id"));
        System.out.println(cat_id);
        CategoryService categoryService = new CategoryServiceImpl();
        try {
            boolean b = categoryService.doDelete(cat_id);
            System.out.println(b);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        resp.sendRedirect("/doCategoryFindAll");


    }
}
